package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

// hello  world my    name is    weizhengxiang
func reverseMessage(message string) string {
	join := strings.Join(strings.Fields(message), " ")
	fmt.Println(join)
	split := strings.Split(join, " ")
	fmt.Println(split)
	for i, j := 0, len(split)-1; i < j; i, j = i+1, j-1 {
		split[i], split[j] = split[j], split[i]
	}
	return strings.Join(split, " ")
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("请输入一段文字（可以包含空格）: ")

	// 读取直到遇到换行符 '\n'，返回包含空格的完整字符串
	input, err := reader.ReadString('\n')
	if err != nil {
		fmt.Println("读取输入出错:", err)
		return
	}
	strings.TrimSpace(input)

	fmt.Println("你输入的是:", input)
	message := reverseMessage(input)
	fmt.Println(message)

}
